<?php
// App::import('Html',"html");
// App::import('Form',"form");
// App::import('Session',"session");
class AppController extends Controller {
	var $components = array('Auth','Session');
	var $helpers = array('Html','Form','Javascript','Session','Utils');	

	function beforeFilter() {
		$this->_handleAuthentication();
		if($this->action!='admin_login') {
			if(substr($this->action, 0, 6) == 'admin_') {
				$this->layout = 'backend/profiadmin';
			}
		}
		Configure::load('my_configs');
	}

	function beforeRender() 
	{
		$this->set('frontend_url', Configure::read('frontend.url'));
	}
	function _handleAuthentication()	{		
		$this->Auth->fields = array('username' => 'username', 'password' => 'password');
		$this->Auth->userScope = array('User.status' => 1);
		$this->Auth->authorize = 'controller';
		$this->Auth->loginAction = '/users/login';
		$this->Auth->loginRedirect = '/admin/home';
		$this->Auth->loginError = 'Wrong user name and/or password';
		$this->Auth->authError = 'Access denied';
		$this->Auth->actionPath = 'controllers/';
		if (substr($this->action, 0, 6) == 'admin_' && !$this->Auth->user()) {
			$this->Auth->deny($this->action);
		}	else {
			$this->Auth->allow($this->action);
		}
	}
}